﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BrainGame
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private List<string> wordList = new List<string> { "A", "B", "C", "D", "E", "F", "G",
                "H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        private List<string> questionList = new List<string>{ "上厕所遇到了奥巴马，奥巴马问：你吃了吗？",
            "天上掉下了林妹妹，林妹妹看到你了，问：你是谁啊，这么丑？" };

        /// <summary>
        /// 第几个题目
        /// </summary>
        private int index = 0;
        
        /// <summary>
        /// 点击下一个字母按钮事件
        /// </summary>
        private void nextWord_Click(object sender, EventArgs e)
        {
            SetWord();
        }

        /// <summary>
        /// 下一道题目场景
        /// </summary>
        private void nextQuestion_Click(object sender, EventArgs e)
        {
            if (nextQuestion.Text == "开始")
            {
                nextWord.Enabled = true;
                nextQuestion.Text = "下一道题目";
            }
            if (index <= questionList.Count - 1)
            {
                var question = questionList[index];
                quesShow.Text = question;
                index++;
                SetWord();
            }
            else
            {
                MessageBox.Show("结束！");
            }
        }

        /// <summary>
        /// 设置字母
        /// </summary>
        private void SetWord()
        {
            var r = new Random();
            var nextValue = r.Next(26);
            showWord.Text = wordList[nextValue];
            countDownTimer.Enabled = true;
            countDownTimer.Start();
            //SetCountDown();
        }

        /// <summary>
        /// timer的事件
        /// </summary>
        private void countDownTimer_Tick(object sender, EventArgs e)
        {
            countDownTimer.Interval = 10;
            theout();
        }

        /// <summary>
        /// 个位
        /// </summary>
        private int aBit = 0;

        /// <summary>
        /// 十分位
        /// </summary>
        private int veryBit = 0;

        /// <summary>
        /// 百分位
        /// </summary>
        private int percentile = 0;

        /// <summary>
        /// 倒计时计数，更新显示倒计时数据
        /// </summary>
        public void theout()
        {
            percentile++;
            if (percentile > 9)
            {
                percentile = 0;
                veryBit++;
            }
            if (veryBit > 9)
            {
                veryBit = 0;
                aBit++;
            }
            if (aBit == 5)
            {
                countDown.Text = "时间到";
                countDownTimer.Stop();//停止计数，各个位数的值清空
                aBit = 0;//个位
                veryBit = 0;//十分位
                percentile = 0;//百分位
            }
            else
                countDown.Text = $@"{aBit}.{veryBit}{percentile}s";
        }

    }
}
